﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace Web.backStage.file
{
    public partial class updateVideo : System.Web.UI.Page
    {
        private Model.Video video;

        protected void Page_Load(object sender, EventArgs e)
        {
                video = BLL.videoLib.VideoManager.GetVideoById(Int32.Parse(Request.QueryString["videoId"]));

                if (!this.IsPostBack)
                {
                    NameTxt.Text = video.VideoName;
                    TypeDropList.SelectedIndex = video.VideoType;
                    PublicDateTxt.Text = video.VideoCreatedDate;
                    ManufactureTxt.Text = video.VideoMaker;
                    HotScoreDropList.SelectedIndex = video.VideohotScore + 1;
                    BriefIntroTxt.Text = video.VideoSummary;
                    DirectorTxt.Text = video.VideoDirector;
                    ActorsTxt.Text = video.VideoActors;
                    LanguageTxt.Text = video.VideoLanguage;
                    LocationTxt.Text = video.VideoNation;
                    //TypeDropList.SelectedValue = video.VideoTypeName;
                    CheckBox1.Checked = video.IsTry;
                }
        }

        protected void SaveBtn_Click(object sender, EventArgs e)
        {

            video.VideoName = NameTxt.Text;
            video.VideoType = TypeDropList.SelectedIndex;
            video.VideoCreatedDate = PublicDateTxt.Text;
            video.VideoMaker = ManufactureTxt.Text;
            if(FileUpload2.HasFile)
            {
                video.VideoImage = "~/poster/" + FileUpload2.FileName;
            }
            video.VideohotScore = HotScoreDropList.SelectedIndex + 1;
            video.VideoSummary = BriefIntroTxt.Text;
            video.VideoDirector = DirectorTxt.Text;
            video.VideoActors = ActorsTxt.Text;
            video.VideoLanguage = LanguageTxt.Text;
            video.VideoNation = LocationTxt.Text;
            if (FileUpload1.HasFile)
            {
                video.VideoURL = "~/movies/" + TypeDropList.SelectedValue + "/" + FileUpload1.FileName;
                video.VideoFileType = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
            }
            //video.VideoUploadDate = DateTime.Now.ToString();
            video.VideoTypeName = TypeDropList.SelectedValue;
            video.IsTry = CheckBox1.Checked;


            //***************************************
            // 各种填各种数据
            //***************************************

            BLL.videoLib.VideoManager.UpdateVideo(video);

            //***************************************
            //上传文件和海报
            //***************************************
            if (FileUpload1.HasFile)
            {
                FileUpload1.PostedFile.SaveAs("D:/movies/" + TypeDropList.SelectedValue + "/" + FileUpload1.FileName);
            }

            if (FileUpload2.HasFile)
            {
                FileUpload2.PostedFile.SaveAs("D:/poster/" + TypeDropList.SelectedValue + "/" + FileUpload2.FileName);
            }

            //Response.Write("<script language=javascript>history.go(-2);</script>");
        }

        protected void CancelBtn_Click(object sender, EventArgs e)
        {
            Response.Write("<script language=javascript>history.go(-2);</script>");
        }
    }
}
